package pers.weiney.mapper;


import org.apache.ibatis.annotations.*;
import pers.weiney.pojo.Article;

import java.util.List;

/**
 * @Author: @Weiney
 * @ClassName: ArticleMapper
 * @Description: 文章数据层接口
 * @Create: 2024-08-13
 **/
@Mapper
public interface ArticleMapper {
    /**
     * @param article
     * @return void
     * @author @Weiney
     * @description 新增文章
     **/
    @Insert("insert into article(title, content, cover_img, state, category_id, create_user, create_time, update_time)" +
            "values(#{title}, #{content}, #{coverImg}, #{state}, #{categoryId}, #{createUser}, #{createTime}, #{updateTime})")
    void insert(Article article);

    /**
     * @param createUser
     * @param categoryId
     * @param state 
     * @return void
     * @author @Weiney
     * @description 分页查询：这里涉及动态SQL，因此使用Mapper.xml映射文件
     **/
    List<Article> selectAllByPage(Integer createUser, Integer categoryId, String state);

    /**
     * @param id
     * @return Article
     * @author @Weiney
     * @description 根据id查询文章详情
     **/
    @Select("select * from article where id=#{id}")
    Article selectById(Integer id);

    /**
     * @param article
     * @return void
     * @author @Weiney
     * @description 更新文章信息
     **/
    @Update("update article set title=#{title}, content=#{content}, cover_img=#{coverImg}, state=#{state}, category_id=#{categoryId} where id=#{id}")
    void updateArticle(Article article);

    /**
     * @param id
     * @return void
     * @author @Weiney
     * @description 根据id删除文章
     **/
    @Delete("delete from article where id=#{id}")
    void deleteById(Integer id);
}
